<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>
    //数据结构
    var a,b,c;
    [a,b] = [10,20];
    console.log(a); //10
    console.log(b); //20

    //对象结构
    ({a,b} = {a:10,b:20});
    console.log(a); //10
    console.log(b); //20

    //...rest 解构数组
    [a,b,...rest] = [10,20,30,40,50];
    console.log(a); //10
    console.log(b); //20
    console.log(rest); //30 40 50

    // ...rest 解构对象 （最新）
    ({a,b,...rest} = {a:10,b:20,c:30,d:40});
    console.log(a); //10
    console.log(b); //20
    console.log(rest); //{c: 30, d: 40}


    //解析一个从函数返回
    function f(){
        return [1,2];
    }
    var a,b;
    [a,b]=f();
    console.log(a); //1
    console.log(b); //2



    //默认值
    [a=5,b=7] = [1];
    console.log(a); //1
    console.log(b); //7
    

    //交换变量
    var a = 1;
    var b = 2;
    [a,b] = [b,a];
    console.log(a); //2
    console.log(b); //1


    //忽略你不感兴趣的返回值
    function f(){
        return [1,2,3];
    }
    var [a, ,b,] = f();
    console.log(a); //1
    console.log(b); //3
</script> 